﻿
        var type = 1;
$(function () {

    get_list(1);
    $('[data-type]').click(function () {
        type = $(this).attr('data-type');
        $('[data-type]').parent().removeClass('cur');
        $(this).parent().addClass('cur');

        get_list(1);
    })
    //$('.btnBack a').click(function () {
    //    window.history.back();
    //})

})
var limit = 1;
function get_list(ty) {
           
    if (ty == 1) {
        $("#lists").html('');
        limit = 1;
    } else {
        //$("#lists").html('<div class="dropload-refresh"  onclick="get_list(0);">卖命加载中...</div>');
    }

    $.ajax({
        type: "post",
        url: "/agentcenter/GetHehuoren",
        data: {
            type: type, limit: limit
        },
        dataType: "json",
        success: function (data) {

            if (data.State == true) {
                var list = data.Datas;
                var content = '';
                for (var i = 0; i < list.length; i++) {


                    content += "<li>";
                    content += '<a href="#" class="clearfix">';
                    content += '<p class="photo"><img src="' + list[i].head_img + '" onerror="javascript:this.src=\'http://0d077ef9e74d8.cdn.sohucs.com/qoO86mG_png\'"></p>';
                    content += ' <div class="desc">';
                    content += ' <h5>' + list[i].nickname + '</h5>';
                    content += '<p>今日销售' + list[i].order_number + '单</p>';

                    content += ' </div>';
                    content += '<h6 class="fl">今日预估￥<span>' + list[i].income + '</span></h6>';
                    content += ' </a> </li>';

                }
                $('#nodate').hide();
                $('#lists').show();
                $("#lists").append(content);


                if (list.length <= 0) {
                    // $("#list_more").html('<div class="nocoll"><p>没有更多记录！~</p></div>');
                    $('#nodate').show();
                    $('#lists').hide();
                }
                limit++;




                //waterfall();
                //lazy_img();
            } else {
                //  $("#list_more").html('<div class="nocoll"><p>您还没有队员哦！~</p></div>');
                //dialog("没有更多记录！！");
                //$("#list_more").fadeOut(500);
                $('#nodate').show();
            }
        },
        error: function (xhr, type) {

        }
    });


}


////==============自动加载=============
//获取滚动条当前的位置
function getScrollTop() {
    var scrollTop = 0;
    if (document.documentElement && document.documentElement.scrollTop) {
        scrollTop = document.documentElement.scrollTop;
    }
    else if (document.body) {
        scrollTop = document.body.scrollTop;
    }
    return scrollTop;
}

//获取当前可是范围的高度
function getClientHeight() {
    var clientHeight = 0;
    if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
    }
    else {
        clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
    }
    return clientHeight;
}

//获取文档完整的高度
function getScrollHeight() {
    return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
}


$(window).scroll(function () {
    if (getScrollTop() + getClientHeight() == getScrollHeight()) {
        //alert("到达底部");
        get_list(0);
    }
});

